package com.gjzt.business.media.controller;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.eastdigit.servlet.ReqBean;
import com.eastdigit.servlet.RequestAttribute;
import com.eastdigit.servlet.Response;
import com.eastdigit.util.StringUtil;
import com.gjzt.business.media.service.MediaResourceService;

@Controller
@RequestMapping(value = "/media/resource")
public class MediaResourceController {

    @Autowired
    private MediaResourceService mediaResourceService;
    

    @RequestMapping(value = "/dynamicBusHead")
    @ResponseBody
    public JSONObject dynamicBusHead(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(mediaResourceService.dynamicBusHead(reqBean));
    }

    @RequestMapping(value = "/dynamicBusData")
    @ResponseBody
    public JSONObject dynamicBusData(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(mediaResourceService.dynamicBusData(reqBean));
    }

    @RequestMapping(value = "/dynamicHeadLength")
    @ResponseBody
    public JSONObject dynamicHeadLength(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(mediaResourceService.dynamicHeadLength(reqBean));
    }

    @RequestMapping(value = "/dynamicResourceDetailsHead")
    @ResponseBody
    public JSONObject dynamicResourceDetailsHead(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(mediaResourceService.dynamicResourceDetailsHead(reqBean));
    }

    @RequestMapping(value = "/runDynamicQuery")
    @ResponseBody
    public JSONObject runDynamicQuery(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(mediaResourceService.runDynamicQuery(reqBean));
    }

    @RequestMapping(value = "/companyInnerTrans")
    @ResponseBody
    public JSONObject companyInnerTrans(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(mediaResourceService.companyInnerTrans(reqBean));
    }

    @RequestMapping(value = "/companyTrans")
    @ResponseBody
    public JSONObject companyTrans(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(mediaResourceService.companyTrans(reqBean));
    }

    @RequestMapping(value = "/vehicleUsing")
    @ResponseBody
    public JSONObject vehicleUsing(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(mediaResourceService.vehicleUsing(reqBean));
    }

    @RequestMapping(value = "/resourceDayQuery")
    @ResponseBody
    public JSONObject resourceDayQuery(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(mediaResourceService.resourceDayQuery(reqBean));
    }

    @RequestMapping(value = "/runDynamicPublish")
    @ResponseBody
    public JSONObject runDynamicPublish(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(mediaResourceService.runDynamicPublish(reqBean));
    }

    @RequestMapping(value = "/runDynamicDetail")
    @ResponseBody
    public JSONObject runDynamicDetail(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(mediaResourceService.runDynamicDetail(reqBean));
    }

    /**
     * 查询车辆资源
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/bus/query")
    @ResponseBody
    public JSONObject queryResourcesOfBus(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(mediaResourceService.queryMediaResourcesOfBus(reqBean));
    }

    /**
     * 查询车辆异动信息
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/bus/transQuery")
    @ResponseBody
    public JSONObject transQuery(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(mediaResourceService.transQuery(reqBean));
    }


    /**
     * 查询站点资源
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/stop/query")
    @ResponseBody
    public JSONObject queryResourcesOfStop(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(mediaResourceService.queryMediaResourcesOfStop(reqBean));
    }
    
    /**
     * 查询所属车辆资源
     * @param reqBean
     * @param busId
     * @return
     */
    @RequestMapping(value = "/list/bus/{busId}")
    @ResponseBody
    public JSONObject findResourcesOfBus(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean,@PathVariable String busId) {
        return Response.response(mediaResourceService.findBusMediaResources(busId));
    }
    
    /**
     * 查询所属站点资源
     * @param reqBean
     * @param stopId
     * @return
     */
    @RequestMapping(value = "/list/stop/{stopId}")
    @ResponseBody
    public JSONObject findResourcesOfStop(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean,@PathVariable String stopId) {
        return Response.response(mediaResourceService.findStopMediaResources(stopId));
    }

    /**
     * 添加点位
     *
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/save")
    @ResponseBody
    public JSONObject saveMediaResource(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
    	if(reqBean.containsKey("resourceId") && !StringUtil.isEmpty(reqBean.getInfo("resourceId"))){
    		mediaResourceService.updateMediaResource(reqBean);
    	}else{
    		mediaResourceService.addMediaResource(reqBean);
    	}
        return Response.responseSuccess();
    }

    /**
     * 删除资源
     *
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/{resourceId}/remove")
    @ResponseBody
    public JSONObject removeMediaResource(final @PathVariable String resourceId) {
        mediaResourceService.removeMediaResource(resourceId);
        return Response.responseSuccess();
    }
    
    /**
     * 恢复资源
     *
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/{resourceId}/revert")
    @ResponseBody
    public JSONObject revertMediaResource(final @PathVariable String resourceId) {
        mediaResourceService.revertMediaResource(resourceId);
        return Response.responseSuccess();
    }
    
    /**
     * 查询资源广告记录
     * @param reqBean
     * @param stopId
     * @return
     */
    @RequestMapping(value = "/ads")
    @ResponseBody
    public JSONObject findAdsOfResource(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(mediaResourceService.findAdsOfResource(reqBean));
    }
    
    /**
     * 查询资源广告记录
     * @param reqBean
     * @param stopId
     * @return
     */
    @RequestMapping(value = "/rights")
    @ResponseBody
    public JSONObject findRightsOfResource(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(mediaResourceService.findRightsOfResource(reqBean));
    }



    /**
     * 导入功能
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/importData")
    @ResponseBody
    public JSONObject importData(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        mediaResourceService.importData(reqBean);
        return Response.responseSuccess();
    }


    /**
     * 导入功能
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/synchronousBus")
    @ResponseBody
    public JSONObject synchronousBus(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) throws Exception {
        return Response.responseSuccess(mediaResourceService.synchronousBus(reqBean));
    }


}